package com.common.help.test11;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class BIOServer {

	int port;
	ServerSocket server;
	//先写服务端
	
	public BIOServer(int port) throws IOException{
		this.port = port;
		server = new ServerSocket(port);
	}
	
	public void listener() throws IOException{
		System.out.println("服务端初始化端口:"+this.port);
		Socket s = server.accept();
		InputStream in = s.getInputStream();
		byte[] b = new byte[1024];
		int len = in.read(b);
		if(len>0){
			System.out.println(new String(b,0,len));
		}
		s.close();
		server.close();
	}
	public static void main(String[] args) throws IOException {
		new BIOServer(8080).listener();
	}
	
}
